import React from 'react'
import { Modal, message } from 'antd';
import { ExclamationCircleOutlined } from '@ant-design/icons';
import {getRes} from "../../../../configFile";
import {userJoinManufacturer} from "../../../../requests/Manufacturer";

//解构出confirm
const { confirm } = Modal;
export default function JoinManufacturerModal(manufacturerID: number, manufacturerName: string, refresh: () => void) {
    confirm({
        title: `确认加入 ${manufacturerName} 吗`,
        icon: <ExclamationCircleOutlined />,
        content: '加入后可在离开厂商页面离开',
        onOk() {
            return userJoinManufacturer(manufacturerID).then(msg => {
                const res=getRes(msg)
                if (res.isSuccessful) {
                    message.success('加入成功')
                    refresh()
                }
                else {
                    message.error('加入失败')
                }
            }).catch((err) => {
                console.log(err)
            })
        },
        onCancel() { },
    });
}